/**
 * 
 */
package org.youisoft.summer.evaluator.function.control;

import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.function.AbstractFunction;
import org.youisoft.summer.evaluator.operator.Operator;

/**
 * @author zijiang.jl
 *
 */
public class SwitchFunction extends AbstractFunction{

	@Override
	public <C,R,P> Operator<?> doInvoke(CalContext<C,R,P> context,Operator<?>... operator) {
		for(int i=1;i<operator.length-1;i=i+2){
			if(operator[0].equals(operator[i])) return operator[i+1];
		}
		
		if(operator.length>this.minOperatorCount()) return operator[operator.length-1];
		return Operator.nullInstance;
	}

	
	
	@Override
	protected int minOperatorCount() {
		return 3;
	}
	
}